package com.xxd.dfs.datanode;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: XiaoDong.Xie
 * @create: 2020-08-24 11:19
 * @description: DataNode组件
 */
public class DataNode {
    private final Logger logger = LoggerFactory.getLogger(DataNode.class);

    private NameNodeRpcClient nameNodeRpcClient;
    private HeartbeatManager heartbeatManager;

    private volatile boolean shouldRun = true;

    public DataNode() {
        this.nameNodeRpcClient = new NameNodeRpcClient();
        heartbeatManager = new HeartbeatManager(nameNodeRpcClient);
        boolean result = nameNodeRpcClient.register();
        if (!result) {
            logger.info("注册失败, datanode启动失败, 关闭进程");
            System.exit(0);
        }

        heartbeatManager.start();
    }

    /**
     * 运行DataNode
     */
    private void start() {
        try {
            while (shouldRun) {
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        DataNode dataNode = new DataNode();
        dataNode.start();
    }
}
